﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Forget.HRBLL.Logical;

namespace HRWebSite.Employee
{
    public partial class ApplyLeave : BasePage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            this.HRLimitAttribute = Forget.HRBLL.LimitAttribute.Read | Forget.HRBLL.LimitAttribute.Add | Forget.HRBLL.LimitAttribute.Delete;
            this.HRLimits = Limits.UserInfo;
            base.Page_Load(sender, e);
            Session["ApplyLeave_NumberID"] = this.HRUser.NumberID;
            this.literal1.Text = string.Format("<script type='text/javascript'>$(document).ready(function () {{$(function () {{$('#{0}').datepicker();}});}});</script>",this.TextBox4.ClientID);
            this.literal2.Text = string.Format("<script type='text/javascript'>$(document).ready(function () {{$(function () {{$('#{0}').datepicker();}});}});</script>", this.TextBox1.ClientID);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime m_start = DateTime.Parse(this.TextBox4.Text + " " + this.TextBox5.Text);
                DateTime m_end = DateTime.Parse(this.TextBox1.Text + " " + this.TextBox3.Text);
                if (m_end > m_start)
                {
                    int type = int.Parse(this.DropDownList1.SelectedValue);
                    if (HolidyInfoLogical.AddHolidyInfo(m_start, m_end, type, this.HRUser.NumberID))
                        this.GridView1.DataBind();
                    else
                        Response.Write("<script>alert('保存失败');</script>");
                }
                else
                    Response.Write("<script>alert('起始时间不能大于结束时间！');</script>");
            }
            catch
            {
                Response.Write("<script>alert('保存失败');</script>");                
            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int holidyID = int.Parse(e.Keys[0].ToString());
            if (HolidyInfoLogical.DelHolidyInfo(holidyID))
                this.GridView1.DataBind();
            e.Cancel = true;
        }

        protected string GetState(string state)
        {
            if (state == "0") return "未审核";
            else if (state == "1") return "未通过";
            else if (state == "2") return "通过";
            return "";
        }
    }
}